﻿using SharpML.Api.Types;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace SharpML.Api.Extensions
{
    public static class SettingsBases
    {
        public static XmlSerializableDictionary<string,object> Serialize( this SettingsBase settings )
        {
            var properties = new XmlSerializableDictionary<string, object>();

            foreach( SettingsProperty property in settings.Properties )
                properties.Add( property.Name, settings.PropertyValues[property.Name] );

            return properties;
        }

        public static void Deserialize( this SettingsBase settings, XmlSerializableDictionary<string,object> data )
        {
            var properties = new Dictionary<string, object>();

            foreach( SettingsProperty property in settings.Properties )
            {
                var propertyName = property.Name;

                if( properties.ContainsKey( propertyName ) )
                    settings[propertyName] = properties[propertyName];
            }
        }
    }
}
